package com.cloudsigns.factorymanager2.engineering.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import android.widget.ImageView;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringConstructContentBean;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;


import java.util.ArrayList;
import java.util.List;

/**
 * 施工内容或计划适配器
 * Created by tony on 2018/1/29.
 */

public class ConstructPlanOrContentAdapter extends BaseAdapter {
    private Context context;
    private List<EngineeringConstructContentBean> datas = new ArrayList<EngineeringConstructContentBean>();
    private LayoutInflater inflater;
    private String tag = "";
    private ItemClickListener itemClickListener;


    public ConstructPlanOrContentAdapter(Context context, String tag) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.tag = tag;
    }

    public void setItemClickListener(ItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    ;

    public void setData(List<EngineeringConstructContentBean> list) {
        this.datas.clear();
        if (null != list) {
            this.datas.addAll(list);
        }

    }


    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public EngineeringConstructContentBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_edit_engineering_construct_order_lv, null);
            holder.tv_content = convertView.findViewById(R.id.tv_content);
            holder.tv_palan_start_date = convertView.findViewById(R.id.tv_palan_start_date);
            holder.tv_plan_end_date = convertView.findViewById(R.id.tv_plan_end_date);
            holder.img_edit_plan_date = convertView.findViewById(R.id.img_edit_plan_date);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        EngineeringConstructContentBean bean = datas.get(position);
//        holder.tv_content.setText(bean.getContent());
//        holder.tv_palan_start_date.setText(bean.getStartDate());
//        holder.tv_plan_end_date.setText(bean.getEndDate());

        holder.img_edit_plan_date.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (itemClickListener != null) {
                    itemClickListener.itemClick(view,position);
                }
            }
        });


        return convertView;
    }

    private class ViewHolder {
        private TextView tv_content;
        private TextView tv_palan_start_date;
        private TextView tv_plan_end_date;
        private ImageView img_edit_plan_date;

    }


}
